package com.ruoyi.activiti.controller;

import com.ruoyi.activiti.domain.ActMaintainOrderData;
import com.ruoyi.activiti.domain.vo.ActMaintainOrderDataVO;
import com.ruoyi.activiti.service.IActMaintainOrderDataService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 表单数据Controller
 *
 * @author cjie
 * @date 2022-04-04
 */
@Api(tags = " 表单数据")
@RestController
@RequestMapping("/actMaintainOrderData")
public class ActMaintainOrderDataController extends BaseController {
    @Autowired
    private IActMaintainOrderDataService actMaintainOrderDataService;

    /**
     * 查询表单数据列表
     */
    @ApiOperation(value="查询表单数据列表", notes="查询表单数据列表")
    @PreAuthorize(hasPermi = "activiti:actMaintainOrderData:list")
    @GetMapping("/list")
    public TableDataInfo list(ActMaintainOrderData actMaintainOrderData) {
        startPage();
        List<ActMaintainOrderData> list = actMaintainOrderDataService.selectActMaintainOrderDataList(actMaintainOrderData);
        return getDataTable(list);
    }

    /**
     * 导出表单数据列表
     */
    @ApiOperation(value="导出表单数据列表", notes="导出表单数据列表")
    @PreAuthorize(hasPermi = "activiti:actMaintainOrderData:export")
    @Log(title = "表单数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActMaintainOrderData actMaintainOrderData) throws IOException {
        List<ActMaintainOrderData> list = actMaintainOrderDataService.selectActMaintainOrderDataList(actMaintainOrderData);
        ExcelUtil<ActMaintainOrderData> util = new ExcelUtil<ActMaintainOrderData>(ActMaintainOrderData.class);
        util.exportExcel(response, list, "表单数据数据");
    }
    /**
     * 获取表单数据详细信息
     */
    @ApiOperation(value="获取表单数据详细信息", notes="获取表单数据详细信息")
    @PreAuthorize(hasPermi = "activiti:actMaintainOrderData:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(actMaintainOrderDataService.selectActMaintainOrderDataById(id));
    }

    /**
     * 获取表单数据详细信息
     */
    @ApiOperation(value="接口获取表单数据详细信息", notes="接口获取表单数据详细信息")
    @PreAuthorize(hasPermi = "activiti:actMaintainOrderData:query")
    @GetMapping(value = "/vo/{id}")
    public AjaxResult getVOInfo(@PathVariable("id") String id) {
        return AjaxResult.success(actMaintainOrderDataService.selectActMaintainOrderDataVOById(id));
    }

    /**
     * 新增表单数据
     */
    @ApiOperation(value="新增表单数据", notes="新增表单数据")
    @PreAuthorize(hasPermi = "activiti:actMaintainOrderData:add")
    @Log(title = "表单数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActMaintainOrderData actMaintainOrderData) {
        return toAjax(actMaintainOrderDataService.insertActMaintainOrderData(actMaintainOrderData));
    }

    /**
     * 业务接口新增表单数据
     */
    @ApiOperation(value="接口新增表单数据", notes="新增表单数据")
    @Log(title = "接口新增表单数据", businessType = BusinessType.INSERT)
    @PostMapping(value="/add")
    public R addData(@RequestBody ActMaintainOrderData actMaintainOrderData) {
        actMaintainOrderDataService.insertActMaintainOrderData(actMaintainOrderData);
        return R.ok(actMaintainOrderData.getId());
    }

    /**
     * 新增表单数据
     */
    @ApiOperation(value="新增表单数据", notes="新增表单数据")
    @PreAuthorize(hasPermi = "activiti:actMaintainOrderData:add")
    @Log(title = "表单数据", businessType = BusinessType.INSERT)
    @PostMapping("/saveFormData")
    public AjaxResult saveFormData(@RequestBody ActMaintainOrderDataVO actMaintainOrderDataVO) {
        return toAjax(actMaintainOrderDataService.insertActMaintainOrderDataVO(actMaintainOrderDataVO));
    }

    /**
     * 接口新增表单数据
     */
    @ApiOperation(value="接口新增表单数据", notes="接口新增表单数据")
    @Log(title = "接口新增表单数据", businessType = BusinessType.INSERT)
    @PostMapping("/remote/saveFormData")
    public R<Integer> remoteSaveFormData(@RequestBody ActMaintainOrderDataVO actMaintainOrderDataVO) {
        return toR(actMaintainOrderDataService.insertActMaintainOrderDataVO(actMaintainOrderDataVO));
    }

    /**
     * 修改表单数据
     */
    @ApiOperation(value="修改表单数据", notes="修改表单数据")
    @PreAuthorize(hasPermi = "activiti:actMaintainOrderData:edit")
    @Log(title = "表单数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActMaintainOrderData actMaintainOrderData) {
        return toAjax(actMaintainOrderDataService.updateActMaintainOrderData(actMaintainOrderData));
    }

    @PutMapping(value = "/edit")
    public R editData(@RequestBody ActMaintainOrderData actMaintainOrderData) {
        return toR(actMaintainOrderDataService.updateActMaintainOrderData(actMaintainOrderData));
    }

    //获取表单数据
    @PostMapping(value = "/getData")
    public R<ActMaintainOrderDataVO> getData(@RequestBody ActMaintainOrderData actMaintainOrderData) {
        return R.ok(actMaintainOrderDataService.selectActMaintainOrderDataVOById(actMaintainOrderData.getId()));
    }

    //updateFormData
    /**
     * 修改表单数据
     */
    @ApiOperation(value="接口修改表单数据", notes="接口修改表单数据")
    @PreAuthorize(hasPermi = "activiti:actMaintainOrderData:edit")
    @Log(title = "表单数据", businessType = BusinessType.UPDATE)
    @PutMapping("/updateFormData")
    public AjaxResult updateFormData(@RequestBody ActMaintainOrderDataVO actMaintainOrderDataVO) {
        return toAjax(actMaintainOrderDataService.updateActMaintainOrderDataVO(actMaintainOrderDataVO));
    }

    /**
     * 删除表单数据
     */
    @ApiOperation(value="删除表单数据", notes="删除表单数据")
    @ApiImplicitParam(name = "ids", value = "表单数据ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "activiti:actMaintainOrderData:remove")
    @Log(title = "表单数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(actMaintainOrderDataService.deleteActMaintainOrderDataByIds(ids));
    }
}
